package com.role
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class LifeBox extends Sprite
	{
		private var txt:TextField;
		public const max:int = 100;
		private var current:int;
		
		private var omax:int;
		private var ocurrent:int;
		public function LifeBox()
		{
			super();
			txt = new TextField();
			txt.width = 100;
			txt.height = 20;
			txt.autoSize = TextFieldAutoSize.CENTER;
			addChild(txt);
		}
		public function init(omax:uint, ocurrent:uint):void{
			this.omax = omax;
			this.ocurrent = ocurrent;
			addLife(0);
		}
		public function addLife(value:int):int{
			ocurrent += value;
			ocurrent = Math.max(0, ocurrent);
			txt.text = ocurrent + "/" + omax;
			refresh();
			return ocurrent;
		}
		public function refresh():void{
			graphics.clear();
			graphics.beginFill(0x00);
			graphics.drawRect(0, 0, max + 2, 14);
			graphics.beginFill(0xff0000);
			graphics.drawRect(1, 1, max / omax * ocurrent, 12);
		}
	}
}